import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:get/get.dart';
import 'package:get/get_navigation/src/root/get_material_app.dart';
import 'package:get/get_navigation/src/routes/transitions_type.dart';
import 'package:smartloan_mdc/pages/auth/code_page.dart';
import 'package:smartloan_mdc/pages/auth/phone_page.dart';
import 'package:smartloan_mdc/pages/home/home_page.dart';
import 'package:smartloan_mdc/pages/splash/splash_page.dart';
import 'package:smartloan_mdc/pages/webview/h5_page.dart';
import 'package:smartloan_mdc/res/theme.dart';
import 'package:smartloan_mdc/route/app_routes.dart';
import 'package:smartloan_mdc/utils/loading/loading.dart';
import 'package:smartloan_mdc/utils/locator/locator.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  SystemChrome.setPreferredOrientations([
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown
  ]);

  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    mainSync();
    
    return ScreenUtilInit(
        designSize: const Size(375, 667),
        builder: (context, child) {
          return GetMaterialApp(
            title: 'SmartLoan_MDC',
            debugShowCheckedModeBanner: false,
            theme: ThemeData(
              primaryColor: AppTheme.mainColor,
              colorScheme: ColorScheme.fromSeed(seedColor: AppTheme.mainColor),
              useMaterial3: true,
            ),
            home: const SplashPage(),
            defaultTransition: Transition.leftToRight,
            builder: EasyLoading.init(
                builder: (context, widget) {
                  return FToastBuilder()(
                      context,
                      MediaQuery(
                        data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
                        child: GestureDetector(
                          onTap: () {
                            // HideKeyBoard();
                          },
                          child: widget!,
                        ),
                      )
                  );
                }
            ),
            // navigatorKey: navigatorKey,
            getPages: [
              GetPage(
                name: AppRoutes.splash,
                page: () => const SplashPage(),
              ),
              GetPage(
                name: AppRoutes.phone,
                page: () => const PhonePage()
              ),
              GetPage(
                name: AppRoutes.code,
                page: () => const CodePage(),
                transition: Transition.rightToLeft
              ),
              GetPage(
                name: AppRoutes.h5,
                page: () => const H5Page()
              ),
              GetPage(
                name: AppRoutes.home,
                page: () => const HomePage()
              ),
            ],
          );
        }
    );
  }

  mainSync() async {
    easyLoadingInit();
    setupLocator();
  }

}


